package xq.demo.excel;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class JxlUtil{
	private String filename;
	private InputStream is;
	private Workbook wb;

	public void setFileName(String filename) {
		this.filename = filename;
	}

	public void setInputStream(InputStream is) {
		this.is = is;
	}
	
	public String getCell(int sheet, int row, int col) {
		if(wb==null) {
			if(filename==null && is==null)
				return null;
			if(is==null) {
				try {
					is = new FileInputStream(filename);
				} catch (FileNotFoundException e) {
					return null;
				}
			}
			try {
				wb = Workbook.getWorkbook(is);
			} catch (BiffException e) {
				return null;
			} catch (IOException e) {
				return null;
			}
		}
		Sheet ws = wb.getSheet(sheet);
		Cell cell = ws.getCell(row, col);
		return cell.getContents();
	}
}
